/**
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the GPL License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.guardianapis.api.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guardianapis.api.domain.jaxb.Content;
import com.guardianapis.api.domain.jaxb.Results;
import com.guardianapis.api.domain.jaxb.Search;
import com.guardianapis.api.domain.jaxb.Tag;
import com.guardianapis.api.domain.jaxb.Tags;

public class Dumper {

	/*******************************************************************************
	 * Constants
	 *******************************************************************************/

	private static Log log = LogFactory.getLog(Dumper.class);

	/*******************************************************************************
	 * Static Public Methods
	 *******************************************************************************/

	public static void dump(Search pSearch) {
		StringBuilder output = new StringBuilder("\nSearch: " + pSearch + "\n");
		if (pSearch != null) {
			output.append("count: " + pSearch.getCount() + "\n");
			output.append("start-index: " + pSearch.getStartIndex() + "\n");
			if (pSearch.getResults() != null) {
				Results results = pSearch.getResults();
				output.append("results count: " + results.getContent().size() + "\n");
				if (results.getContent() != null) {
					for (Content currentContent : results.getContent()) {
						output.append("Content: " + currentContent.getHeadline() + "\n");
					}
				}
			}
		}
		
		log.info(output);
	}
	
	public static void dump(Content pContent) {
		StringBuilder output = new StringBuilder("\nContent: " + pContent + "\n");
		if (pContent != null) {
			output.append("id: " + pContent.getId() + "\n");
			output.append("headline: " + pContent.getHeadline() + "\n");
			output.append("api-url: " + pContent.getId() + "\n");
		}
		
		log.info(output);
	}

	public static void dump(Tags pTags) {
		StringBuilder output = new StringBuilder("\nTags: " + pTags + "\n");
		output.append("count: " + pTags.getCount() + "\n");
		output.append("start-index: " + pTags.getStartIndex() + "\n");
		if (pTags != null) {
			for (Tag currentTag : pTags.getTag()) {
				output.append("Tag name: " + currentTag.getName() + " ");
				output.append("type: " + currentTag.getType() + "\n");
			}
		}
		log.info(output);
	}
	
	public static void dump(String pXml) {
		log.info(pXml);
	}
	
}
